/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package systole.view.settings.report;

import java.io.File;
import javax.swing.filechooser.FileFilter;

/**
 *
 * @author jmj
 */
public class ImageFileFilter extends FileFilter {

    protected final static String jpeg = "jpeg";
    protected final static String jpg = "jpg";
    protected final static String gif = "gif";
    protected final static String tiff = "tiff";
    protected final static String tif = "tif";
    protected final static String png = "png";


    /**
     * @param f
     * @return file extension
     */
    public String getExtension(File f) {
        String ext = null;
        String s = f.getName();
        int i = s.lastIndexOf('.');

        if (i > 0 && i < s.length() - 1) {
            ext = s.substring(i + 1).toLowerCase();
        }
        return ext;
    }

    @Override
    public boolean accept(File f) {

        if (f == null) {
            return false;
        }

        if (f.isDirectory()) {
            return false;
        }

        String extension = this.getExtension(f);
        if (extension != null) {
            if (extension.equals(ImageFileFilter.tiff)
                    || extension.equals(ImageFileFilter.tif)
                    || extension.equals(ImageFileFilter.gif)
                    || extension.equals(ImageFileFilter.jpeg)
                    || extension.equals(ImageFileFilter.jpg)
                    || extension.equals(ImageFileFilter.png)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public String getDescription() {
        return "Archivo de Imágen";
    }
}
